﻿@using Abp.Extensions
@model Abp.Application.Services.Dto.ListResultDto<FutureApp.Shop.Dto.GoodsBrandEntityDto>

@section Scripts{
    <script>
        !function ($) {

            var $$$ = function () {
                this.$box = $('.box');
                this.service = abp.services.app.goodsBrand;
                this.localize = abp.localization.localize;
            };
            $$$.prototype = {
                init: function () {
                    this.binding();
                },
                binding: function () {
                    var self = this;
                    this.$box.on("click", '.btn', function (e) {
                        var $sender = $(e.currentTarget);
                        var action = $.trim($sender.data("action"));
                        var uniqueid = $sender.parents("tr").data("uniqueid");
                        switch (action) {
                            case "disable":
                                self.disableGoodsBrand(uniqueid);
                                break;
                            case "enable":
                                self.enableGoodsBrand(uniqueid);
                                break;
                            case "delete":
                                self.deleteGoodsBrand(uniqueid);
                                break;
                        }
                    });
                },
                enableGoodsBrand: function (uniqueid) {
                    var self = this;
                    abp.message.confirm(self.localize("AskEnableGoodsBrand"))
                        .done(function (isConfirm) {
                            if (!isConfirm) return;
                            abp.ui.setBusy(self.$box);
                            abp.timing.wait(100).done(function () {
                                self.service.enableGoodsBrand(uniqueid).done(function () {
                                    abp.message.success(self.localize("EnableGoodsBrandSucceed"))
                                        .done(function () { location.reload(true); });
                                }).always(function () {
                                    abp.ui.clearBusy(self.$box);
                                });
                            });
                        });
                },
                disableGoodsBrand: function (uniqueid) {
                    var self = this;
                    abp.message.confirm(self.localize("AskDisableGoodsBrand"))
                        .done(function (isConfirm) {
                            if (!isConfirm) return;
                            abp.ui.setBusy(self.$box);
                            abp.timing.wait(100).done(function () {
                                self.service.disableGoodsBrand(uniqueid).done(function () {
                                    abp.message.success(self.localize("DisableGoodsBrandSucceed"))
                                        .done(function () { location.reload(true); });
                                }).always(function () {
                                    abp.ui.clearBusy(self.$box);
                                });
                            });
                        });
                },
                deleteGoodsBrand: function (uniqueid) {
                    var self = this;
                    abp.message.confirm(self.localize("AskDeleteGoodsBrand"))
                        .done(function (isConfirm) {
                            if (!isConfirm) return;
                            abp.ui.setBusy(self.$box);
                            abp.timing.wait(100).done(function () {
                                self.service.deleteGoodsBrand(uniqueid).done(function () {
                                    abp.message.success(self.localize("DeleteGoodsBrandSucceed"))
                                        .done(function () { location.reload(true); });
                                }).always(function () {
                                    abp.ui.clearBusy(self.$box);
                                });
                            });
                        });
                }
            };

            $(function () { (new $$$()).init(); });
        }(jQuery);
    </script>
}

<ul class="content-nav">
    <li class="active">
        <a href="javascript:;">@L("List")</a>
    </li>
    <li>
        <a href="@Url.Action("add")">@L("Add")</a>
    </li>
</ul>
<div class="box box-success box-edge-all" data-dock="true">
    <table data-toggle="table"
           data-show-columns="true"
           data-show-pagination-switch="true"
           data-show-refresh="true"
           data-search="true"
           data-pagination="true"
           data-key-events="true">
        <thead>
            <tr>
                <th data-sortable="true">@L("GoodsBrandName")</th>
                <th>@L("Operation")</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var mdl in this.Model.Items)
            {
                <tr data-uniqueid="@mdl.Id">
                    <td>@mdl.Name</td>
                    <td class="center-block">
                        <a class="btn btn-danger btn-xs" href="javascript:;" data-action="delete">@L("Delete")</a>
                        @if (mdl.IsActive)
                        {
                            <a class="btn btn-danger btn-xs" href="javascript:;" data-action="disable">@L("Disable")</a>
                        }
                        else
                        {
                            <a class="btn btn-success btn-xs" href="javascript:;" data-action="enable">@L("Enable")</a>
                        }
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>